<!--
 * @Description: 
 * @Author: charles
 * @Date: 2020-11-03 14:05:02
 * @LastEditors: charles
 * @LastEditTime: 2021-08-01 14:07:59
-->
<template>
  <div class="details">
    <h2>{{data.title}}</h2>
    <div class="time">{{data.publishTime | fmtDate}}</div>
    <div class="wrapper" v-html="data.content"></div>
    <div class="btn">
    <el-button class="button" type="primary" plain @click="thumbUp(data.id)">点赞</el-button>
    </div>
  </div>
</template>
<script>
import { get } from "../utils/request";
export default {
  data() {
    return {
      id: "",
      data: {},
    };
  },
  methods: {
    //查询项目的详细信息
    findArticleDetails() {
      get("/index/article/findById?id=" + this.id).then((res) => {
        // console.log(res);
        if (res.status == 200) {
          this.data = res.data;
        } else {
          this.$message({
            type: "error",
            message: res.message,
          });
        }
      });
    },
    //点赞文章
    thumbUp(id){
      get('/index/article/thumbUp',{id:id}).then((res)=>{
        // console.log(res);
        if(res.status == 200){
          this.$message({
          message: '点赞成功',
          type: 'success'
        });
        }else{
          this.$message.error('点赞失败');
        }
      })
    }
  },
  created() {
    //拿到从上一个页面传过来的id值
    this.id = this.$route.query.id;
    //调用查询详细信息的方法
    this.findArticleDetails();
  },
};
</script>
<style lang="scss" scoped>
.details{
  width: 70%;
  margin: 0 auto;
  h2,.time{
    text-align: center;
  }
  .btn{
    text-align: center;
  }
}
</style>